//
//  NavigationBar.m
//  LotteryClient
//
//  Created by Suny on 14-7-7.
//  Copyright (c) 2014年 CTTC. All rights reserved.
//

#import "NavigationBar.h"
#import "UIImage+BaseFramework.h"

@implementation NavigationBar

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        // Initialization code
        self.titleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor], UITextAttributeTextColor,
                                                                              nil];

        // Settitletext attributes
        NSMutableDictionary *attributes = [[NSMutableDictionary alloc] init];

        [attributes setValue:[UIColor blackColor]
                      forKey:UITextAttributeTextColor];
        [attributes setValue:[UIColor whiteColor]
                      forKey:UITextAttributeTextShadowColor];
        [attributes setValue:[NSValue valueWithUIOffset:UIOffsetMake(0, 1)]
                      forKey:UITextAttributeTextShadowOffset];
        [attributes setValue:[UIFont systemFontOfSize:0.0]
                      forKey:UITextAttributeFont];

        self.titleTextAttributes = attributes;


    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];

    UIView *subview = [self viewWithTag:kNavigationItemAlignment_HL_VC];
    if (subview)
    {
        CGRect frame = subview.frame;
        frame.origin.x = 10;
        frame.origin.y = (CGFloat) ((CGRectGetHeight(self.bounds) - CGRectGetHeight(frame)) * 0.5 + kDefaultNavigationDelY);
        subview.frame  = frame;
    }

    subview = [self viewWithTag:kNavigationItemAlignment_HR_VC];
    if (subview)
    {
        CGRect frame = subview.frame;
        frame.origin.x = CGRectGetWidth(self.bounds) - CGRectGetWidth(frame) - 10;
        frame.origin.y = (CGFloat) ((CGRectGetHeight(self.bounds) - CGRectGetHeight(frame)) * 0.5 + kDefaultNavigationDelY);
        subview.frame  = frame;
    }

    subview = [self viewWithTag:kNavigationItemAlignment_HC_VC];
    if (subview)
    {
        CGRect frame = subview.frame;
        frame.origin.x = (CGFloat) ((CGRectGetWidth(self.bounds) - CGRectGetWidth(frame)) * 0.5);
        frame.origin.y = (CGFloat) ((CGRectGetHeight(self.bounds) - CGRectGetHeight(frame)) * 0.5 + kDefaultNavigationDelY);
        subview.frame  = frame;
    }

    if (_shadowImageView && _shadowImageView.superview)
    {
        _shadowImageView.frame = CGRectMake(0, CGRectGetHeight(self.bounds), CGRectGetWidth(self.bounds), 0.5);
    }
}


- (void)setCustomShadowImage:(UIImage *)shadowImage
{
    if (_shadowImageView == nil)
    {
        _shadowImageView = [[UIImageView alloc] initWithImage:[shadowImage stretchableImageByWidthCenter]];
    }
    else
    {
        _shadowImageView.image = [shadowImage stretchableImageByWidthCenter];
    }

    _shadowImageView.frame = CGRectMake(0,
                                        (CGFloat) (CGRectGetHeight(self.bounds) - 0.5),
                                        CGRectGetWidth(self.bounds),
                                        0.5);

    if (_shadowImageView.superview == nil)
    {
        _shadowImageView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth;
        [self addSubview:_shadowImageView];
    }
}

- (void)dealloc
{

}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
